package org.jdcenter.face;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class PluginsConfig {
	
	public final static String jmxType = "jmxType";
	public final static String telnetType = "telnetType";
	public final static String socketType = "socketType";
	public final static String rmiType = "rmiType";
	public final static String webserviceType = "webserviceType";
	public final static String cacheType = "cacheType";
	public final static String clusterType = "clusterType";
	public final static String jmsType = "jmsType";
	public final static String jndiType = "jndiType";
	public final static String aopType = "refType";
	public final static String refType = "refType";
	
	private static Map<String,ConcurrentHashMap<String,Boolean>> plugins = new ConcurrentHashMap<String,ConcurrentHashMap<String,Boolean>>();
	
	public static void addPlugin(String pluginType,String implType,String isDefault){
		ConcurrentHashMap<String,Boolean> plugin = plugins.get(pluginType);
		if(plugin == null){
			plugin = new ConcurrentHashMap<String,Boolean>();
			plugins.put(pluginType, plugin);
		}
		Boolean flag = Boolean.FALSE;
		if(isDefault.equalsIgnoreCase("true")){
			flag = Boolean.TRUE;
		}
		plugin.putIfAbsent(implType, flag);
	}
	
	public static String getDefImplType(String pluginType){
		ConcurrentHashMap<String,Boolean> plugin = plugins.get(pluginType);
		if(plugin == null){
			return null;
		}
		for(String key : plugin.keySet()){
			if(plugin.get(key)){
				return key;
			}
		}
		return null;
	}

}
